package com.kaching.twitter
  
import org.junit.Test
import org.junit.Assert._ 
import com.kaching.twitter._

@Test
class TestTwitterParsing {
  
  @Test def testParsingLinkRequests {
    "should not parse" match {
      case KCActor.LinkRequest(id, key) => fail("should not work")
      case _ => //great
    }
    "61208 dame1779glue" match {
      case KCActor.LinkRequest(id, key) => {
        assertEquals("61208", id)
        assertEquals("dame1779glue", key)
      }
      case _ => fail("should have worked")
    }
    " 61208 dame1779glue " match {
      case KCActor.LinkRequest(id, key) => {
        assertEquals("61208", id)
        assertEquals("dame1779glue", key)
      }
      case _ => fail("should have worked")
    }
  }
 
  @Test def testParsingOrderRequests {
    "should not parse" match {
      case Order(order) => fail("should not work")
      case _ => //great
    }
    "@kc_trade $$ buy 100 $GOOG" match {
      case Order(order) => fail("should not work")
      case _ => //great
     }
    ("@kc_trade buy 100 $GOOG" :: "@kc_trade $GOOG buy 100 $$ comment" :: Nil) foreach {
       case Order(order) => {
         assertEquals(Buy, order.action)
         assertEquals(100, order.amount)
         assertEquals("GOOG", order.symbol)
         assertEquals(Market(), order.orderType)
       }
       case _ => fail("should have worked")
     }
    ("@kc_trade buy 100 $GOOG $100 $$ Some comment" :: 
      "@kc_trade buy $GOOG 100 $100  " :: 
      "@kc_trade  100 long $GOOG @100" :: 
      "@kc_trade $GOOG 100 @100 buy " :: 
       Nil) foreach {
       case Order(order) => {
         assertEquals(Buy, order.action)
         assertEquals(100, order.amount)
         assertEquals("GOOG", order.symbol)
         assertEquals(Limit(100), order.orderType)
       }
       case _ => fail("should have worked")
     }
    ("@kc_trade sell 100 $IBM $100 $$ Some comment" :: 
      "@kc_trade sell $IBM 100 $100  " :: 
      "@kc_trade sell 100 $IBM @100" :: 
      "@kc_trade $IBM sell 100 @100" :: 
       Nil) foreach {
       case Order(order) => {
         assertEquals(Sell, order.action)
         assertEquals(100, order.amount)
         assertEquals("IBM", order.symbol)
         assertEquals(Limit(100), order.orderType)
       }
       case _ => fail("should have worked")
     }
    ("@kc_trade short 100 $G1OG $100 $$ Some comment" :: 
      "@kc_trade short $G1OG 100 $100  " :: 
      "@kc_trade  100 short $G1OG @100" :: 
      "@kc_trade $G1OG 100 @100 short " :: 
       Nil) foreach {
       case Order(order) => {
         assertEquals(Short, order.action)
         assertEquals(100, order.amount)
         assertEquals("G1OG", order.symbol)
         assertEquals(Limit(100), order.orderType)
       }
       case _ => fail("should have worked")
     }
    ("@kc_trade cover 100 $ABC.A $100 $$ Some comment" :: 
      "@kc_trade cover $ABC.A 100 $100  " :: 
      "@kc_trade  100 cover $ABC.A @100" :: 
      "@kc_trade $ABC.A 100 @100 cover " :: 
       Nil) foreach {
       case Order(order) => {
         assertEquals(Cover, order.action)
         assertEquals(100, order.amount)
         assertEquals("ABC.A", order.symbol)
         assertEquals(Limit(100), order.orderType)
       }
       case _ => fail("should have worked")
     }
  }
}
